package org.qf.Test;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.qf.Dao.supermarketDao;
import org.qf.entity.supermarket;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class Showtest {
    public static void main(String[] args) {
//1.加载mybatis核心配置文件
        try {
            InputStream inputStream = Resources.getResourceAsStream("mybatis-config.xml");
//2.获取会话工厂
            SqlSessionFactoryBuilder builder=new SqlSessionFactoryBuilder();
            SqlSessionFactory factory=builder.build(inputStream);
//3.获取会话
            SqlSession session = factory.openSession();
//4. 获取dao接口
            supermarketDao studentDao = session.getMapper(supermarketDao.class);
//
//            List<Student> list = studentDao.showList();
//
//            for(Student student:list){
//                System.out.println(student.getStuNum()+"\t"+student.getStuName()+"\t"+student.getStuGender());
//            }
//
//            //设置当前页面的容量
            PageHelper.startPage(1,3);

            List<supermarket> list = studentDao.showSupermarket("");

            PageInfo<supermarket> pageInfo = new PageInfo<supermarket>(list);
            System.out.println("-------------------分页-----------------");
            System.out.println("当前页："+pageInfo.getPageNum());
            System.out.println("一页显示的条数："+pageInfo.getPageSize());
            System.out.println("总条数："+pageInfo.getTotal());
            System.out.println("总页数："+pageInfo.getPages());
            System.out.println("-------------------数据-----------------");

            for(supermarket student: pageInfo.getList()){
                System.out.println(student.getStuName()+"\t"+student.getStuNum()+"\t"+student.getStuType()+"\t"+student.getStuWeight());
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
